﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Gebra.Test
{
    [TestClass]
    public class DivideTest
    {
        [TestMethod]
        public void ConstructWithNumbers()
        {
            var operand = new Divide(a_numerator: (Number) 64, a_denomenator: (Number) 8);

            var result = operand.Evaluate() as Number;

            Assert.IsNotNull(result);
            Assert.AreEqual(8, (double) result);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void ConstructWithNullNumerator()
        {
            new Divide(a_numerator: null, a_denomenator: (Number) 8);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void ConstructWithNullDenomenator()
        {
            new Divide(a_numerator: (Number) 64, a_denomenator: null);
        }

        [TestMethod]
        public void EvaluateThreeDividsions()
        {
            // (64 / 8) / 4 = 2
            var operand = new Number(64).Divide(8).Divide(4);

            var result = operand.Evaluate() as Number;

            Assert.IsNotNull(result);
            Assert.AreEqual(2, (double) result);
        }

        [TestMethod]
        public void EvaluationDivisionWithMultiplication()
        {
            // (64 / 8) * 4 = 32
            var operand = new Number(64).Divide(8).Multiply(4);

            var result = operand.Evaluate() as Number;

            Assert.IsNotNull(result);
            Assert.AreEqual(32, (double) result);
        }

        [TestMethod]
        public void EvaluationDevisionWithMultiplicationReversingOrderOfOperations()
        {
            // 64 / (8 * 4) = 2
            var operand = new Number(64).Divide(new Number(8).Multiply(4));

            var result = operand.Evaluate() as Number;

            Assert.IsNotNull(result);
            Assert.AreEqual(2, (double) result);

        }
    }
}
